using System;
using System.Linq;

namespace LeetCodeSolutions
{
    /// <summary>
    /// 58. 最后一个单词的长度
    /// </summary>
    public class LeetCode58: LeetCodeBase
    {
        public override void Execute()
        {
            string s = "   fly me   to   the moon  ";
            CommonFuntions.Print(LengthOfLastWord(s));
        }

        public int LengthOfLastWord(string s)
        {
            int count = 0;
            for (int i = s.Length - 1; i >= 0; i--)
            {
                if (s[i] != ' ')
                {
                    count++;
                }
                else
                {
                    if (count != 0)
                    {
                        break;
                    }
                }
            }

            return count;
        }
    }
}